package com.grm.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * 返回结果模板类
 *
 * @author gaorimao
 * @date 2022/02/07
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result {
    private int code;
    private String message;
    private Object data;
    private Long total;

    /**
     * 成功
     *
     * @param message 消息
     * @return {@link Result}
     */
    public static Result success(String message) {
        return new Result(200, message, null, null);
    }

    /**
     * 成功
     *
     * @param message 消息
     * @param data    数据
     * @return {@link Result}
     */
    public static Result success(String message, Object data) {
        return new Result(200, message, data, null);
    }

    /**
     * 成功
     *
     * @param message 消息
     * @param data    数据
     * @param total   总计
     * @return {@link Result}
     */
    public static Result success(String message, Object data, Long total) {
        return new Result(200, message, data, total);
    }

    /**
     * 失败
     *
     * @param code    代码
     * @param message 消息
     * @return {@link Result}
     */
    public static Result failed(int code, String message) {
        return new Result(code, message, null, null);
    }

    /**
     * 结果
     *
     * @param code    代码
     * @param message 消息
     * @param data    数据
     * @param total   总计
     */
    public Result(int code, String message, Object data, Long total) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
    }
}
